﻿using Design.Common.Attri;
using Design.Common.Interface;
using Design.Common.Model;
using Design.Common.Utils;
using System.Reflection;

namespace SingletonPattern
{
    [DesignAttribute(nameof(Singleton), DesignType.Creation, (int)CreationType.Singleton)]
    public class Singleton : IDesignDemo
    {
        public DesignAttribute GetDesignAttribute() => typeof(Singleton).GetCustomAttribute<DesignAttribute>();

        public void RunExample(bool isRun)
        {
            if (!isRun) return;
            Parallel.For(0, 10, (i) => { var temp = LazybonesSingleton.Instance; });
            Parallel.For(0, 10, (i) => { var temp = LazybonesInterlockSingleton.Instance; });
            Parallel.For(0, 10, (i) => { var temp = HungryManSngleton.Instance; });
            Parallel.For(0, 10, (i) => { var temp = SystemLazySingleton.Instance; });
            Parallel.For(0, 10, (i) => { var temp = DoubleLazybonesSingleton.Instance; });
            Parallel.For(0, 10, (i) => { var temp = NestedClassSingleton.Instance; });
        }
    }
}